<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class City extends Model
{
    use SoftDeletes;
    // 表名称
    protected $table = 'city';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';
	//批量赋值
	protected $fillable =['status','slogan','summary'];

	protected $appends = ['status_bool'];

    public function followedUser()
    {
        return $this->belongsToMany('App\Users','user_follow_city', 'city_id', 'user_id');
    }

    public function user()
    {
        return $this->belongsToMany('App\Users','user_mapping_city', 'city_id', 'user_id');
    }

    public function cafe(){
		return $this->hasMany('App\Cafe','citycode','code');
	}

    public function tags(){
        return $this->hasManyThrough('App\Cafes_tags', 'App\Cafe','citycode','cafe_id','id');
    }

    // 追加status_bool字段,status的布尔类型
    public function getStatusBoolAttribute()
    {
        return $this->attributes['status'] ? 'true' : false;
    }

}
